<template>
  <div class="ffddsa">
    <div class="boxfvg1" v-for="(item) in DataList" :key="item.id">
      <span class="boxfvg1Ttles">{{ item.name || "" }}</span>
      <div class="progress-barsdff1">
        <transition name="progress-bar-transition">
          <div class="progress-bar-fill" :style="{ width: item.progress + '%', backgroundColor: item.color }">
          </div>
        </transition>
      </div>
      <span class="boxfvg1tootersss">{{ item.value }}笔</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      DataList: [
        // 初始化 8 条摩托车信息
        { id: 1, value: 2344, name: "OJMOTOR", color: "#5470c6", progress: 0 },
        { id: 2, value: 2001, name: "春风", color: "#91cc75", progress: 0 },
        { id: 3, value: 1893, name: "无极", color: "#fac858", progress: 0 },
        { id: 4, value: 1653, name: "蒙爵铃木", color: "#ee6666", progress: 0 },
        { id: 5, value: 1455, name: "赛科龙", color: "#73c0de", progress: 0 },
        { id: 6, value: 1244, name: "豪爵", color: "#3ba272", progress: 0 },
        { id: 7, value: 1156, name: "阿普利亚 RS 660", color: "#fc8452", progress: 0 },
        { id: 8, value: 890, name: "凯旋 Street Triple", color: "#9a60b4", progress: 0 },
      ],
      colorData: [
        "#5470c6",
        "#91cc75",
        "#fac858",
        "#ee6666",
        "#73c0de",
        "#3ba272",
        "#fc8452",
        "#9a60b4",
      ],
    };
  },
  mounted() {
    this.startProgress();
  },
  methods: {
    startProgress() {
      const totalItems = 100;
      let current = 0;

      const timer = setInterval(() => {
        current++;
        this.DataList.forEach((item) => {
          item.progress = (current * item.value) / totalItems;
        });

        if (current === totalItems) {
          clearInterval(timer);
        }
      }, 1);
    },
  },
};
</script>

<style scoped>
.boxfvg1 {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.boxfvg1 .boxfvg1Ttles {
  width: 150px;
  margin-right: 10px;
  font-size: 16px;
  color: aliceblue;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* background-color: #fff; */
}

.boxfvg1 .boxfvg1tootersss {
  width: 150px;
  margin-left: 10px;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* color: rgb(113, 251, 220); */
  margin-right: 5px;
}

.progress-barsdff1 {
  display: inline-block;
  width: 100%;
  height: 16px;
  background-color: rgb(38, 86, 178);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 8px;
}

.progress-bar-transition-enter-active,
.progress-bar-transition-leave-active {
  transition: width 0.5s;
}

.progress-bar-transition-enter,
.progress-bar-transition-leave-to {
  width: 0;
}

.progress-bar-label {
  position: absolute;
  top: 0;
  right: 8px;
  bottom: 0;
  display: flex;
  align-items: center;
  color: white;
  font-size: 12px;
}
</style>